package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-15 18:06
 **/
public class LeetCode1716 {


    //等差数列
    public int totalMoney(int n) {
        //计算完整周存的钱
        int num = n / 7;
        int firstWeekMoney = 28;
        int lastWeekMoney = 28 + (num - 1) * 7;
        int sum = num * (firstWeekMoney + lastWeekMoney) / 2;
        //计算不完整的周存的钱
        int firstDay = num + 1;
        int dayNum = n % 7;
        int lastDay = firstDay + dayNum - 1;
        sum += (firstDay + lastDay) * dayNum / 2;
        return sum;
    }

    //暴力
    /*public int totalMoney(int n) {
        int pre = 1;
        int cur = 1;
        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            sum += cur;
            ++cur;
            if (i % 7 == 0) {
                cur = pre + 1;
                pre = cur;
            }
        }
        return sum;
    }*/

}
